<?php
class CustomerController{
	
	function findAll(){
		$objDB = $GLOBALS['objDB'];
		$rsCustomers = $objDB->Execute("SELECT * FROM customer ;");		
		$customers = array();
		while (!$rsCustomers->EOF){
			$customer = new Customer($rsCustomers->fields['ID'],$rsCustomers->fields['EMAIL'],$rsCustomers->fields['UID']);
			$customers[] = $customer;
			$rsCustomers->MoveNext();
		}
		return $customers;
	}

	function find($uid){
		$objDB = $GLOBALS['objDB'];
		$rsCust = $objDB->Execute("SELECT * FROM customer WHERE UID='$uid' ;");
		if(!$rsCust->EOF){
			$cust = new Customer($rsCust->fields['UID'],$rsCust->fields['ADDRESS'],$rsCust->fields['EMAIL'],$rsCust->fields['PHONE'],$rsCust->fields['CELL'],$rsCust->fields['BIRTHDAY'],$rsCust->fields['TYPE']);
		}else{
			$cust = new Customer("guest","","","","","","");
		}
		return $cust;
	}
	
	function save($entCustomer){
		$objDB = $GLOBALS['objDB'];
		$rscCustomer0 = $objDB->Execute("SELECT * FROM customer WHERE UID='-1';");
		$arrRecords['UID']		=$entCustomer->uid;
		$arrRecords['ADDRESS']	=$entCustomer->address;
		$arrRecords['EMAIL']   	=$entCustomer->email;
		$arrRecords['PHONE']   	=$entCustomer->phone;
		$arrRecords['CELL']   	=$entCustomer->cell;
		$arrRecords['BIRTHDAY']	=$entCustomer->birthday;
		$arrRecords['TYPE']   	=$entCustomer->type;
		$strInserSql = $objDB->GetInsertSQL($rscCustomer0,$arrRecords);
		$objDB->Execute($strInserSql); 
		return true;
	}
	
	function update($entCustomer){
		$objDB = $GLOBALS['objDB'];
		if ($objDB->Execute("UPDATE customer SET ADDRESS='$entCustomer->address', EMAIL='$entCustomer->email', PHONE='$entCustomer->phone', CELL='$entCustomer->cell' WHERE UID='$entCustomer->uid' ;")){
			return true;
		}else {
			return false;
		}
	}
	
	
}
?>